/**
 * author:Administrator
 * date:2016/2/23
 * desc: 一个shop只有一个keeper
 */
'use strict';
let FormatDate = require('../../../infrastructure/appUtil/FormatDate.js');
let Repo = require('./ShopRepo.js');

let STATUS_ENUM = {
  ok: 'ok', // 该店铺ok
  na: 'na', // not available
};
class Shop {

  constructor(pojo) {
    pojo = pojo || {};
    this.id = pojo.id;
    this.vendorId = pojo.vendorId;
    this.name = pojo.name;
    this.locationId = pojo.locationId;

    this.status = pojo.status || STATUS_ENUM.ok;
    this.keeperId = pojo.keeperId;
    this.imgUrls = pojo.imgUrls;
    this.addr = pojo.addr;
    this.openTime = pojo.openTime;
    this.closeTime = pojo.closeTime;
    this.tel = pojo.tel;
    this.desc = pojo.desc;
    this.createdAt = pojo.createdAt || FormatDate.unixTimestamp();
    this.updatedAt = pojo.updatedAt || FormatDate.unixTimestamp();
  }

  * store() {
    this.updatedAt = FormatDate.unixTimestamp();
    return yield Repo.store(this);
  }

  * setKeeper(keeperId) {
    this.keeperId = keeperId;
    yield this.store();
  }
}

module.exports = Shop;